package com.xbongbong.paas.connection.enums;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

@Getter
public enum OpenAppEnum {

	/**
	 *
	 */
	MEI_KE_BAO_XIAO(7872, "每刻报销", "meike", "/pro/v1/connection/callback"),
	ESIGN(0, "e签宝", "esign", "/pro/v1/connection/esignCallback"),
	CLOUD_CODE(5555, "云叩", "cloud_code", "/pro/v1/connection/cloudCodeCallback"),
	DD_CONNECTOR(0, "钉钉连接器(执行动作接收)", "dd_connector", "/pro/v1/connection/ddAction"),
	;

	/** 枚举值 -- 第三方应用id*/
	private final Integer openAppId;

	/** 枚举信息--第三方应用中文名称 */
	private final String name;

	/** 枚举信息 --第三方应用英文名称，用于缓存及其他的地方的key*/
	private final String alias;

	private final String callBackUrl;

	/**
	 * 构造一个<code>OpenAppEnum</code>枚举对象
	 *
	 * @param openAppId
	 * @param name
	 * @param alias
	 */
	private OpenAppEnum(Integer openAppId, String name, String alias, String callBackUrl) {
		this.openAppId = openAppId;
		this.name = name;
		this.alias = alias;
		this.callBackUrl = callBackUrl;
	}

	/**
	 * 通过枚举<code>alias</code>获得枚举
	 *
	 * @param alias
	 * @return OpenAppEnum
	 */
	public static OpenAppEnum getByAlias(String alias) {
		for (OpenAppEnum cacheCode : values()) {
			if (cacheCode.getAlias().equals(alias)) {
				return cacheCode;
			}
		}
		return null;
	}

	/**
	 * 通过枚举<code>alias</code>获得枚举
	 *
	 * @param callBackUrl
	 * @return OpenAppEnum
	 */
	public static OpenAppEnum getByCallBackUrl(String callBackUrl) {
		for (OpenAppEnum cacheCode : values()) {
			if (cacheCode.getCallBackUrl().equals(callBackUrl)) {
				return cacheCode;
			}
		}
		return null;
	}

	/**
	 * 通过枚举<code>openAppId</code>获得枚举
	 *
	 * @param openAppId
	 * @return OpenAppEnum
	 */
	public static OpenAppEnum getByOpenAppId(Integer openAppId) {
		for (OpenAppEnum cacheCode : values()) {
			if (openAppId.equals(cacheCode.getOpenAppId())) {
				return cacheCode;
			}
		}
		return null;
	}

	/**
	 * 获取全部枚举
	 *
	 * @return List<OpenAppEnum>
	 */
	public List<OpenAppEnum> getAllEnum() {
		List<OpenAppEnum> list = new ArrayList<OpenAppEnum>();
		for (OpenAppEnum cache : values()) {
			list.add(cache);
		}
		return list;
	}

	/**
	 * 获取全部枚举值
	 *
	 * @return List<String>
	 */
	public List<String> getAllEnumAlis() {
		List<String> list = new ArrayList<String>();
		for (OpenAppEnum cache : values()) {
			list.add(cache.getAlias());
		}
		return list;
	}

}
